// Load the predefined panorama
function loadPredefinedPanorama(evt) {
	evt.preventDefault();

	var div = document.getElementById('container');
	var srchtml=canvas.toDataURL("sun.jpg");

	var PSV = new PhotoSphereViewer({
		// Path to the panorama
		panorama: srchtml,

		// Container
		container: div,

		// Deactivate the animation
		time_anim: false,

		// Display the navigation bar
		navbar: true,

		// Resize the panorama
		size: {
			width: '100%',
			height: '500px'
		}
	});
}

function convertImgToBase64(url, callback, outputFormat) {
	var canvas = document.createElement('CANVAS'),
		ctx = canvas.getContext('2d'),
		img = new Image();
	//img.crossOrigin = 'Anonymous';
	img.setAttribute("crossOrigin", "anonymous");
	img.onload = function () {
		canvas.height = img.height;
		canvas.width = img.width;
		ctx.drawImage(img, 0, 0);
		var dataURL = canvas.toDataURL(outputFormat || 'image/jpeg');
		callback.call(this, dataURL);
		canvas = null;
	};
	img.src = url;
}

// Load a panorama stored on the user's computer
function upload(url) {
	var div = document.getElementById('your-pano');

	convertImgToBase64(url, function (base64Img) {
		var PSV = new PhotoSphereViewer({
			// Panorama, given in base 64
			panorama: base64Img,

			// Container
			container: div,

			// Deactivate the animation
			time_anim: false,

			// Display the navigation bar
			navbar: true,

			// Resize the panorama
			size: {
				width: '100%',
				height: '500px'
			}
		});
	});
}
